package com.ltz.service.well;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.ltz.dao.well.ObservationRecordDao;
import com.ltz.dao.well.WellDao;
import com.ltz.model.ObservationRecord;
import com.ltz.model.Page;
import com.ltz.model.User;
import com.ltz.model.WellBasicData;

@Service
public class ObservationRecordService {
	@Resource
	private ObservationRecordDao obsRecordDao;
	@Resource
	private WellDao wellDao;
	public Page loadList(Page page,String queryStr){
		String sql="select rec.*,w.name as wellName from observation_record rec left join well_basic_data w on rec.well_id=w.id where w.name like ? order by rec.date_input desc";
		return obsRecordDao.loadList(page,sql,new Object[]{"%"+queryStr+"%"});
	}

	public boolean doAddWell(User user,ObservationRecord w){
		w.setId(null);
		w.setDateInput(new Date());
		w.setOwner(user.getUsername());
		obsRecordDao.add(w);
		return true;
	}
	public boolean doUpdateWell(User user,ObservationRecord w){
		ObservationRecord rec=(ObservationRecord) obsRecordDao.get(ObservationRecord.class, w.getId());
		w.setDateInput(rec.getDateInput());
		w.setOwner(rec.getOwner());
		obsRecordDao.update(w);
		return true;
	}
	public boolean doDeleteWell(int recordId){
		obsRecordDao.delete(ObservationRecord.class, recordId);
		return true;
	}
	public List getWellList(){
		return wellDao.getWellList();
	}
}
